/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author ODHeroes
 */
@Entity
@Table(name = "products")
@NamedQueries({
    @NamedQuery(name = "Products.findAll", query = "SELECT p FROM Products p"),
    @NamedQuery(name = "Products.findByCode", query = "SELECT p FROM Products p WHERE p.code = :code"),
    @NamedQuery(name = "Products.findByCreatedAt", query = "SELECT p FROM Products p WHERE p.createdAt = :createdAt"),
    @NamedQuery(name = "Products.findByProductsId", query = "SELECT p FROM Products p WHERE p.productsId = :productsId"),
    @NamedQuery(name = "Products.findByProductPresentationsId", query = "SELECT p FROM Products p WHERE p.productPresentationsId = :productPresentationsId"),
    @NamedQuery(name = "Products.findByName", query = "SELECT p FROM Products p WHERE p.name = :name"),
    @NamedQuery(name = "Products.findBySlug", query = "SELECT p FROM Products p WHERE p.slug = :slug"),
    @NamedQuery(name = "Products.findByUpdateAt", query = "SELECT p FROM Products p WHERE p.updateAt = :updateAt")})
public class Products implements Serializable {
    private static final long serialVersionUID = 1L;
    @Size(max = 256)
    @Column(name = "code")
    private String code;
    @Column(name = "created_at")
    @Temporal(TemporalType.DATE)
    private Date createdAt;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "products_id")
    private BigDecimal productsId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "product_presentations_id")
    private BigInteger productPresentationsId;
    @Size(max = 256)
    @Column(name = "name")
    private String name;
    @Size(max = 256)
    @Column(name = "slug")
    private String slug;
    @Column(name = "update_at")
    @Temporal(TemporalType.DATE)
    private Date updateAt;
    @JoinTable(name = "tiene_5", joinColumns = {
        @JoinColumn(name = "products_id", referencedColumnName = "products_id")}, inverseJoinColumns = {
        @JoinColumn(name = "prodcuts_brands_id", referencedColumnName = "prodcuts_brands_id")})
    @ManyToMany
    private Collection<ProductBrands> productBrandsCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "productsId")
    private Collection<ProductProbes> productProbesCollection;
    @JoinColumn(name = "nick", referencedColumnName = "nick")
    @ManyToOne
    private Login nick;
    @JoinColumn(name = "category_id", referencedColumnName = "category_id")
    @ManyToOne(optional = false)
    private ProductCategories categoryId;
    @JoinColumn(name = "products_id", referencedColumnName = "product_presentations_id", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private ProductPresentations productPresentations;

    public Products() {
    }

    public Products(BigDecimal productsId) {
        this.productsId = productsId;
    }

    public Products(BigDecimal productsId, BigInteger productPresentationsId) {
        this.productsId = productsId;
        this.productPresentationsId = productPresentationsId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public BigDecimal getProductsId() {
        return productsId;
    }

    public void setProductsId(BigDecimal productsId) {
        this.productsId = productsId;
    }

    public BigInteger getProductPresentationsId() {
        return productPresentationsId;
    }

    public void setProductPresentationsId(BigInteger productPresentationsId) {
        this.productPresentationsId = productPresentationsId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public Collection<ProductBrands> getProductBrandsCollection() {
        return productBrandsCollection;
    }

    public void setProductBrandsCollection(Collection<ProductBrands> productBrandsCollection) {
        this.productBrandsCollection = productBrandsCollection;
    }

    public Collection<ProductProbes> getProductProbesCollection() {
        return productProbesCollection;
    }

    public void setProductProbesCollection(Collection<ProductProbes> productProbesCollection) {
        this.productProbesCollection = productProbesCollection;
    }

    public Login getNick() {
        return nick;
    }

    public void setNick(Login nick) {
        this.nick = nick;
    }

    public ProductCategories getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(ProductCategories categoryId) {
        this.categoryId = categoryId;
    }

    public ProductPresentations getProductPresentations() {
        return productPresentations;
    }

    public void setProductPresentations(ProductPresentations productPresentations) {
        this.productPresentations = productPresentations;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productsId != null ? productsId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Products)) {
            return false;
        }
        Products other = (Products) object;
        if ((this.productsId == null && other.productsId != null) || (this.productsId != null && !this.productsId.equals(other.productsId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Model.Products[ productsId=" + productsId + " ]";
    }
    
}
